package com.kirayous.task3.utils;


import com.kirayous.task3.entity.regionState;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class TaskOfScheduler {

    private  static List<regionState> DataList=new ArrayList<>();


    @Scheduled(cron = "0 0 1 * * *")
    public static boolean updateData() throws IOException {


        DataList=VirusDataGetter.fetchAll();
        if (DataList==null||DataList.size()==0) return false;
        return true;
    }


    public static List<regionState> getDataList() throws IOException {
        if (DataList.size()==0)
            updateData();
        return DataList;
    }




}
